<?php

namespace System;

class Request {

    private static $_instance = NULL;
    private $params;

    private function __construct() {
        
    }

    public function getParams() {
        return $this->params;
    }

    public function __get($name) {
        return $this->params[$name];
    }

    public function __set($name, $value) {
        $this->params[$name] = $value;
    }

    public static function getInstance() {
        if (self::$_instance == NULL) {
            self::$_instance = new Request;
        }

        return self::$_instance;
    }

    public function setParams($params, $requiredParams) {
        $tmp = array();

        if (count($params)) {
            foreach ($params as $index => $param) {
                if (isset($requiredParams[$index])) {
                    $index = $requiredParams[$index];

                    $this->$index = $param;
                } else {
                    $tmp[] = $param;
                }
            }
            if (count($tmp)) {
                $this->params = array_merge($this->params, $tmp);
                $this->params = array_merge($this->params, $_REQUEST);
            }
        }
    }

}
